package com.sw.dubbo.web.filter;

import com.sw.study.web.util.RequestContext;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;

/**
 * @author wodezuiaishinageren
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIpFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        RpcContext.getContext().setAttachment("ip", (String)RequestContext.getContext().getObject("ip"));
        return invoker.invoke(invocation);
    }
}
